package br.com.winesys.geta.editor;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JComponent;

public class WarningDecorator extends AbstractComponentDecorator {

  private static final Image IMAGE;
  private static final int SIZE = 16;

  static {
    try {
      IMAGE = ImageIO.read(WarningDecorator.class.getResourceAsStream("/images/error.gif"));
    } catch (IOException ex) {
      throw new RuntimeException("Unable to find error icon", ex);
    }
  }

  public WarningDecorator(JComponent f) {
    super(f);
  }

  @Override
  public Rectangle getDecorationBounds() {
    Rectangle r = super.getDecorationBounds();
//    Insets insets = getComponent().getInsets();
    r.x += r.width;
    r.y += (r.height - SIZE) / 2;
//    if (insets != null) {
//      r.x += insets.right;
//    }
    return r;
  }

  @Override
  public void paint(Graphics graphics) {
    Rectangle r = getDecorationBounds();
    Graphics2D g2 = (Graphics2D) graphics;
    g2.drawImage(IMAGE, r.x, r.y, null);
  }
}